package com.data.modules.message.handle.executor;

import cn.hutool.core.collection.CollectionUtil;
import lombok.extern.slf4j.Slf4j;

import java.util.Collection;
import java.util.function.Supplier;

/**
 * <p>
 * AbstractMessageSend
 * </p>
 *
 * @author li
 * @version 1.0
 * @date 2022-03-24 19:00
 * @since 1.0
 */
@Slf4j
public class MessageExecutor {

    /**
     * 执行
     *
     * @param supplier
     */
    public static <T> void execute(Supplier<Collection<T>> supplier, MessageSend<T> messageSend) {
        Collection<T> list = supplier.get();
        if (CollectionUtil.isEmpty(list)) {
            return;
        }
        list.forEach(message -> {
            messageSend.afterSend(message, () -> messageSend.send(message));
        });
    }


}
